package future优化.回调版的future;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

/**
 * @author ZhuQi
 * @ClassName ProjectTask
 * @Date 2022/9/5 14:04
 * @Version 1.0
 * @Description 任务
 */
@Slf4j
public class ProjectTask implements Callable<String> {


    @Override
    public String call() throws Exception {
        String threadName = Thread.currentThread().getName();
        log.info(threadName + ":开始执行任务");
        TimeUnit.SECONDS.sleep(ThreadLocalRandom.current().nextInt(10));
        success();
        return threadName + ":任务完成";
    }

    public void success() {
        SuccessThreadList.setThreadId(Thread.currentThread().getId());
    }
}
